<template>
    <div :class="[navBar.isBlue?'bg01':'','navBar']">
        <div class="left" v-if="navBar.back" @click="back()">
            <van-icon name="arrow-left" :color="navBar.isBlue?'#fff':'#fff'" />
        </div>
        <div class="close" v-if="navBar.close">
            <van-icon name="cross" :color="navBar.isBlue?'#fff':'#000'" />
        </div>
        <div class="center">
            {{navBar.title}}
        </div>
        <div class="btn" v-if="navBar.btn" @click="okBtn()">{{navBar.btn}}</div>
        <div class="isicon" v-if="navBar.isicon" @click="okBtn()">
            <van-icon :name="navBar.iname" size="0.9rem" :color="navBar.icolor"/>
        </div>
    </div>
</template>
<script>
// import {isSys} from '../utils/isSystem.js'
export default {
    name: 'navBar',
    components: {},
    props: ['navBar','callback'],
    data () {
        return {
        };
    },
    methods: {
        back(){
            this.$router.go(-1);
            // let history = sessionStorage.getItem("history");
            // if (history) {
            //     history = JSON.parse(history);
            //     console.log(history.length)
            //     if(history.length <= 1){
            //         window.android.backPressed()
            //     }else{
            //         history.pop();
            //         sessionStorage.setItem("history",JSON.stringify(history))
            //         this.$router.go(-1)
            //     }
            // } else {
            //     // if(isSys() == 'Android'){
            //         window.android.backPressed()
            //     // }
            // }
        },
        // 回调函数保存
        okBtn(){
            this.callback()
        }
    },
    mounted () {
        let arr = [];
        let history = sessionStorage.getItem("history");
        let hash = window.location.hash;
        if(!history){
            arr.push(hash);
            sessionStorage.setItem("history",JSON.stringify(arr))
        }else{
            history = JSON.parse(history);
            if(history.indexOf(hash)<0){
                history.push(hash);
                sessionStorage.setItem("history",JSON.stringify(history))
            }
        }
    },
    watch: {

    }
}
</script>
<style scoped lang="scss">
.navBar{
    width: 100%;
    height: 40px;
    background: #181f2f;
    position: absolute;
    left: 0px;
    top: 0px;
    color: #fff;
    z-index: 100;
    &.bg01 {
        color: #fff;
        background: rgb(41, 121, 255);
    }
    .left{
        position: absolute;
        left: 6px;
        top: 4px;
        z-index: 1;
        font-size: 24px;
		font-weight: 500;
        icon {
            display: block;
        }
    }
    .close{
        position: absolute;
        left: 36px;
        top: 4px;
        z-index: 1;
        font-size: 24px;
        display: block;
        icon {
            display: block;
        }
    }
    .center{
        margin: 0 auto;
        width: 235px;
        height: 40px;
        line-height: 40px;
        font-size: 16px;
        // font-weight: 700;
        text-align: center;
        display: block;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
    }
    .btn{
        position: absolute;
        right: 14px;
        top: 10px;
        z-index: 1;
        font-size: 14px;
        display: block;
    }
    .isicon{
        position: absolute;
        right: 14px;
        top: 0px;
        z-index: 1;
        height: 40px;
        display: flex;
        align-items: center;
        icon{
            display: block;
        }
    }
    
}
</style>